package com.sky.mapper;


import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * The interface Shopping cart mapper.
 */
@Mapper
public interface ShoppingCartMapper {

    /**
     * 根据用户id,套餐id,菜品id,口味查询购物车
     *
     * @param shoppingCart the shopping cart
     * @return the shopping cart
     */
    List<ShoppingCart> select(ShoppingCart shoppingCart);

    /**
     * 更新购物车中的菜品或套餐的数量
     *
     * @param cart the cart
     */
    @Update("update shopping_cart set number = #{number} where id = #{id}")
    void updateNumber(ShoppingCart cart);


    /**
     * 添加购物车中的菜品或套餐
     *
     * @param shoppingCart the shopping cart
     */
    @Insert("insert into shopping_cart(name, image, user_id, dish_id, setmeal_id, dish_flavor, number, amount, create_time)  " +
            "values(#{name}, #{image}, #{userId}, #{dishId}, #{setmealId}, #{dishFlavor}, #{number}, #{amount}, #{createTime})")
    void insert(ShoppingCart shoppingCart);


    /**
     * 查询购物车中的菜品或套餐
     *
     * @param shoppingCart the shopping cart
     * @return the list
     */
    @Select("select id, name, image, user_id, dish_id, setmeal_id, dish_flavor, number, amount, create_time from shopping_cart where user_id = #{userId}")
    List<ShoppingCart> selectList(ShoppingCart shoppingCart);


    /**
     * 删除购物车中的菜品或套餐
     *
     * @param shoppingCart the shopping cart
     */
    @Delete("delete from shopping_cart where user_id = #{userId}")
    void deleteByUserId(ShoppingCart shoppingCart);


    /**
     * 删除购物车中的某一个菜品或套餐
     *
     * @param shoppingCart the shopping cart
     */
    void deleteByCondition(ShoppingCart shoppingCart);

    /**
     * 批量插入购物车数据
     *
     * @param shoppingCartList
     */
    void insertBatch(List<ShoppingCart> shoppingCartList);
}
